package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EnvironmentalCourses;
import com.ruoyi.system.service.IEnvironmentalCoursesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * coursesController
 * 
 * @author zrj
 * @date 2025-07-12
 */
@RestController
@RequestMapping("/system/courses")
public class EnvironmentalCoursesController extends BaseController
{
    @Autowired
    private IEnvironmentalCoursesService environmentalCoursesService;

    /**
     * 查询courses列表
     */
    @PreAuthorize("@ss.hasPermi('system:courses:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnvironmentalCourses environmentalCourses)
    {
        startPage();
        List<EnvironmentalCourses> list = environmentalCoursesService.selectEnvironmentalCoursesList(environmentalCourses);
        return getDataTable(list);
    }

    /**
     * 导出courses列表
     */
    @PreAuthorize("@ss.hasPermi('system:courses:export')")
    @Log(title = "courses", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EnvironmentalCourses environmentalCourses)
    {
        List<EnvironmentalCourses> list = environmentalCoursesService.selectEnvironmentalCoursesList(environmentalCourses);
        ExcelUtil<EnvironmentalCourses> util = new ExcelUtil<EnvironmentalCourses>(EnvironmentalCourses.class);
        util.exportExcel(response, list, "courses数据");
    }

    /**
     * 获取courses详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:courses:query')")
    @GetMapping(value = "/{courseId}")
    public AjaxResult getInfo(@PathVariable("courseId") Long courseId)
    {
        return success(environmentalCoursesService.selectEnvironmentalCoursesByCourseId(courseId));
    }

    /**
     * 新增courses
     */
    @PreAuthorize("@ss.hasPermi('system:courses:add')")
    @Log(title = "courses", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnvironmentalCourses environmentalCourses)
    {
        return toAjax(environmentalCoursesService.insertEnvironmentalCourses(environmentalCourses));
    }

    /**
     * 修改courses
     */
    @PreAuthorize("@ss.hasPermi('system:courses:edit')")
    @Log(title = "courses", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnvironmentalCourses environmentalCourses)
    {
        return toAjax(environmentalCoursesService.updateEnvironmentalCourses(environmentalCourses));
    }

    /**
     * 删除courses
     */
    @PreAuthorize("@ss.hasPermi('system:courses:remove')")
    @Log(title = "courses", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courseIds}")
    public AjaxResult remove(@PathVariable Long[] courseIds)
    {
        return toAjax(environmentalCoursesService.deleteEnvironmentalCoursesByCourseIds(courseIds));
    }
}
